package com.neuedu.mybatis.util;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.InputStream;

/**
 * 项目：      mybatis
 * 类名:       SessionFactoryUtils
 * 创建时间：  2024/3/6 08：36
 * 描述 :
 * 作者 :     张金山
 * QQ :     314649444
 * Site:      https://jshand.gitee.io
 */
public class SessionFactoryUtils {

    private static SqlSessionFactory sqlSessionFactory = null;


    public static synchronized SqlSessionFactory getInstance() throws IOException {
        if(sqlSessionFactory == null) {
            String resource = "SqlMapConfig.xml";
            InputStream inputStream = Resources.getResourceAsStream(resource);
            sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);
        }
        return  sqlSessionFactory;
    }


}
